package com.psychology.controller;

import com.psychology.service.AppointmentService;
import com.psychology.util.Result;
import com.psychology.vo.AppointmentVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/appointments")
@Slf4j
public class AppointmentController {

    @Autowired
    private AppointmentService appointmentService;

    @GetMapping("/user")
    public Result<List<AppointmentVO>> getUserAppointments(
            @RequestParam(required = false) String status,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate) {
        try {
            List<AppointmentVO> appointments = appointmentService.getUserAppointments(status, startDate, endDate);
            return Result.success(appointments);
        } catch (Exception e) {
            log.error("获取预约记录失败", e);
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/{id}/cancel")
    public Result<?> cancelAppointment(@PathVariable Long id) {
        try {
            appointmentService.cancelAppointment(id);
            return Result.success();
        } catch (Exception e) {
            log.error("取消预约失败", e);
            return Result.error(e.getMessage());
        }
    }
}